var storage = require('../../util/storage');
var config = require('../../config');

Page({
    data: {
    },
    onLoad: function (options) {
    },
    getPhoneNumber: function (e) {
        console.log(e.detail)
        var that = this;
        if (e.detail.errMsg == "getPhoneNumber:ok") {
          wx.request({
            url: config.getApi("wx_user_decodephone"),
            data: {
              encryptedData: e.detail.encryptedData,
              iv: e.detail.iv,
              cloudId: e.detail.cloudID,
              sessionKey: storage.get('sessionKey'),
              openid: storage.get('openid')
            },
            method: "post",
            success: function (res) {
              console.log(res);
              storage.put('needPhoneAuth',false);
              wx.switchTab({
                url: '/pages/mine/mine',
              })
            },
            fail: function (res) {
              console.log(res);

            }
          });
        }else{
          //todo
        }
    },
    cancelAuth:function(e){
      wx.switchTab({
        url: '/pages/index/index',
      })
    }
});